package com.zx.mes.rabbitmq.hyl.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Fanout:转发消息到所有绑定队列
 * @author hyl
 * @date 2018-3-19
 */
@Configuration
public class FanoutRabbitConfig {

    private static final Logger logger = LoggerFactory.getLogger(FanoutRabbitConfig.class);

    private static final String QUEUE_FANOUT_A="fanout.A";
    private static final String QUEUE_FANOUT_B="fanout.B";
    private static final String QUEUE_FANOUT_C="fanout.C";

    private static final String FANOUT_EXCHANGE = "fanoutExchange";


    @Bean
    public Queue AQueue(){
        return new Queue(QUEUE_FANOUT_A);
    }

    @Bean
    public Queue BQueue(){
        return new Queue(QUEUE_FANOUT_B);
    }

    @Bean
    public Queue CQueue(){
        return new Queue(QUEUE_FANOUT_C);
    }

    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange(FANOUT_EXCHANGE);
    }

    @Bean
    Binding bindingExchangeA(Queue AQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(AQueue).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeB(Queue BQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(BQueue).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeC(Queue CQueue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(CQueue).to(fanoutExchange);
    }
}
